/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BAIntroGuideViewController.m
//  redia-bapps-ios
//
//  Created by Henrik Lynbech on 12/02/14.
//  Copyright (c) 2014 redia. All rights reserved.
//

#import "BAIntroGuideViewController.h"
#import "BALightFrameButton.h"
#import "BARootViewController.h"

@interface BAIntroGuideViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *mainScroller;
@property (weak, nonatomic) IBOutlet BALightFrameButton *skipIntroButton;

@end

@implementation BAIntroGuideViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    NSString* device = @"";
    
    if (RD_IS_IPAD) {
        device = @"-ipad";
        
    } else if (RD_IS_IPHONE5) {
        device = @"-568h";
    }
    
    CGFloat currentX=0;
    CGFloat currentY = ([BAUtils instance].iOSMajorVersion < 7) ? -20 : 0;
    CGFloat lastHeight=480;
    
    for (int i=1; i<=3; i++) {
        NSString* imagename = [NSString stringWithFormat:@"slide-%d%@.jpg",i,device];
        UIImage* newSlideImage = [UIImage imageNamed:imagename];
        DLog(@"intro image '%@', %@",imagename, newSlideImage);
        
        CGSize dimensions = newSlideImage.size;
        UIImageView* newView = [[UIImageView alloc] initWithImage:newSlideImage];
        [self.mainScroller addSubview:newView];
        newView.frame = CGRectMake(currentX, currentY, dimensions.width, dimensions.height);
        lastHeight = dimensions.height;
        currentX += dimensions.width;
    }
    [self.mainScroller setContentSize:CGSizeMake(currentX, lastHeight + currentY)];
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)skipIntroButtonClicked:(id)sender {
    self.skipIntroButton.enabled=NO;
    [[BARootViewController instance] dismissIntroGuide:self];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.mainScroller.contentOffset.x > (self.mainScroller.contentSize.width - (self.mainScroller.bounds.size.width*1.25))) {
        [self.skipIntroButton setTitle:@"START APP" forState:UIControlStateNormal];
    } else {
        [self.skipIntroButton setTitle:@"SKIP INTRO" forState:UIControlStateNormal];
    }
}
@end
